package cn.bocweb.spinning.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.Product1Bean;
import cn.bocweb.spinning.view.common.MyAdapter;


/**
 * Created by chenchangxing on 15/12/17.
 */
public class ProductListAdapter extends MyAdapter<Product1Bean.DataBean> {


    public ProductListAdapter(Context context, List<Product1Bean.DataBean> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_product_list, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }

        Glide.with(context)
                .load(list.get(position).getPhoto())
                .placeholder(R.mipmap.banner_empty)
                .into(holder.img);

        holder.product.setText(list.get(position).getTitle());
        holder.company.setText(list.get(position).getCompany());
        holder.content.setText(list.get(position).getContent());

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.img)
        ImageView img;
        @Bind(R.id.product)
        TextView product;
        @Bind(R.id.company)
        TextView company;
        @Bind(R.id.content)
        TextView content;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
